// ActionScript file
import com.xsky.dataGrid.DataProxy;

import flash.events.MouseEvent;

import mx.controls.Alert;
import mx.controls.Button;

public function initTools(toolsTemplate:XML):void
{
	for each(var item:XML in toolsTemplate.func)
	{
		if(item.@type=="button")
		{
			var button:Button = new Button();
			button.label=item.@label;
			button.name = item.@method;
			if(item.@event=="click")
			{
				button.addEventListener(MouseEvent.CLICK,buttonClick);
			}
			button.setStyle("fontWeight","normal");
			toolHbox.addChild(button);
		}
	}
}
public function buttonClick(event:MouseEvent):void
{
	var eventName:String = event.target.name;
	if(eventName=="insert")
	{
		if(params["userProxy"]=="true")
		{
			var dataProxy:DataProxy = new DataProxy();
			dataProxy.addData(params["tableName"],this);
		}
		else
		{
			addPanel.visible = true;
			addPanel.width=400;
		}
	}
	else if(eventName=="delete")
	{
		var data:String = "<data table=\""+params["tableName"]+"\">" + 
				dataGrid.dataProvider.toString()
				+"</data>";
		var webSrv:WebSrv = new WebSrv(params["gridService"]);
		var paramObj:Object=new Object();
		paramObj["in0"]=data;
		webSrv.invokeWebSrv("delete", paramObj);
		webSrv.onComplete=function(result:String):void
		{
			mx.controls.Alert.show(result);
		    search();
		}
	}
	
}